package core.java;

import org.apache.commons.lang3.ArrayUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author ssk
 * @Title: Stream
 * @ProjectName SpringInAction
 * @Description: TODO
 * @date 19-1-8下午11:17
 *
 * 参考 https://www.cnblogs.com/CarpenterLee/p/6729368.html https://cloud.tencent.com/developer/article/1187833
 */
public class StreamStudy {
    public static void main(String[] args) {
        Integer a[]={1,2,3,6,5,4};
        Arrays.stream(a).forEachOrdered(b->System.out.print(b+" "));
        System.out.println();
        System.out.println(Arrays.stream(a).allMatch(b->b<3));
        System.out.println(ArrayUtils.toString(Arrays.stream(a).filter(b->b>3).distinct().reduce((sum, b)->sum>0?(int)sum+b:b).get()));
        System.out.println(ArrayUtils.toString(Arrays.stream(a).filter(b->b>3).collect(Collectors.toCollection(ArrayList::new))));
        Map map = new HashMap();
        map.put(1,2);
        map.put(2,3);
        map.put(3,4);
        System.out.println(ArrayUtils.toString(map.entrySet().stream().filter((b)->(Integer) ((Map.Entry)b).getValue()!=3).toArray()));
    }
}
